<template>
  <div class="topnav">
    <div class="logo">
      LOGO
    </div>
    <ul class="menu">
      <li>菜单1</li>
      <li>菜单2</li>
    </ul>
    <div class="toggleAside"
         @click="toggleMenu"></div>
  </div>
</template>


<script lang='ts'>
import { inject } from "vue";
export default {
  name: "Topnav",
  setup() {
    // const menuVisible = inject<Ref<boolean>>("xxx"); // get
    const menuVisible = inject("menuVisible"); // get
    // console.log("topnav 获取的 menuVisible " + menuVisible.value);
    const toggleMenu = () => {
      menuVisible.value = !menuVisible.value;
    };
    return { toggleMenu };
  },
};
</script>

<style scoped lang="scss">
.topnav {
  background-color: pink;
  display: flex;
  padding: 16px;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 10;
  justify-content: center;

  > .logo {
    max-width: 6em;
    margin-right: auto;
  }
  > .menu {
    display: flex;
    // 字不会换行
    white-space: nowrap;
    // 盒子不会换行
    flex-wrap: nowrap;

    > li {
      margin: 0 1em;
    }
  }

  > .toggleAside {
    width: 24px;
    height: 24px;
    background-color: red;
    // display: inline-block;
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
  }

  @media (max-width: 500px) {
    > .menu {
      display: none;
    }

    > .toggleAside {
      display: block;
    }

    > .logo {
      margin: 0 auto;
    }
  }
}
</style>
